﻿using UnityEngine;
using System.Collections;
using Configs;

public class MonsterObject : IUnitObject
{
    public MonsterObject(IStage stage, ConfUnitObject confUnitObject) : base(stage, confUnitObject)
    {
        GetModule().GetOrNew<ModAI>();
        GetModule().Get<ModAI>().SwitchOnAI(new MonsterAI(GetSelfOwnerObj()));

        GetModule().GetOrNew<ModBlood>().SetOffsetPos(new Vector3(0, 1.5f, 0));
    }
   
    public static void OnEventAttack(IUnitObject unitObj, bool start)
    {
        if (!(unitObj is MonsterObject))
        {
            return;
        }

        if (start)
        {
            // 攻击开始
            unitObj.GetUnityGameObject().SetAnmiTrigger("Attack");
        }
    }

    public static void OnEventLossHp(IUnitObject unitObj, int hp, IUnitObject attackUnitObj)
    {
        if (!(unitObj is MonsterObject))
        {
            return;
        }

        Debug.Log("MonsterObject[" + unitObj.GetId() + "]losshp:" + hp);

        unitObj.GetModule().Get<ModDamage>().BeDamaged(hp);
    }

    public static void OnEventDead(IUnitObject unitObj, IUnitObject attackUnitObj)
    {
        if (!(unitObj is MonsterObject))
        {
            return;
        }

        Debug.Log("怪物死亡了：" + unitObj.GetId());

        if (unitObj.GetModule().Get<ModAttr>().GetGroup() == ModAttr.GROUP_BLUE)
        {
            UIManager.GetInstance().GetUI<MainUI>().ChangeEnergy(2);
        }
    }
}
